﻿using AbpVnext_Module.Permission;
using Ebusiness_Application;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Account;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.AutoMapper;
using Volo.Abp.Identity;
using Volo.Abp.Modularity;
using Volo.Abp.PermissionManagement;
using Volo.Abp.PermissionManagement.Identity;
using Volo.Abp.TenantManagement;

namespace AbpVnext__Comon
{
    /// <summary>
    /// 所有的项目，抽象成AbpModule
    /// 方便使用和维护。
    ///  项目服务隔离 ，好处：独立维护
    /// </summary>
    [DependsOn(
        typeof(ApplicationContractsMoudule),
        typeof(DomainMoudule),
        typeof(AbpAutoMapperModule)
                //配置应用模块
                , typeof(AbpPermissionManagementApplicationModule)
                , typeof(AbpIdentityApplicationModule)
                  , typeof(AbpAccountApplicationModule)
                , typeof(AbpTenantManagementApplicationModule)
         //配置应用身份认证模块
         , typeof(AbpPermissionManagementDomainIdentityModule)
        )]
    public class ApplicationMobileMoudule : AbpModule
    {
        /// <summary>
        /// 依赖注入
        /// </summary>
        /// <param name="context"></param>
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            //base.ConfigureServices(context); 依赖注入 代码注册
            //context.Services.AddTransient<IUserService, UserService>();

            //context.Services.AddTransient<IProductAppService, ProductAppService>();

            //配置automap dto映射
            Configure<AbpAutoMapperOptions>(option => option.AddMaps<ApplicationMobileMoudule>());

            ////配置自定义鉴权类
            Configure<AbpPermissionOptions>(option =>
            {
                //当注册多个权限值提供者时，PermissionGrantResult.Prohibited;
                //当其中有一个返回值为Prohibited，会直接返回403，授权没有通过
                //当返回值没有Prohibited,其中有一个返回值为Granted,则代表授权通过
                //当返回值全部为Undefined,,则代表授权没有通过
                option.ValueProviders.Add(typeof(CustomPermissionValueProvider));
                option.ValueProviders.Add(typeof(ProductPermissionValueProvider));
            });
        }
    }
}
